package com.smartleanx.module.hrm.controller.admin.companysystemtype;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import com.smartleanx.framework.security.core.annotations.PreAuthenticated;
import com.smartleanx.module.hrm.controller.admin.companysystemtype.vo.CompanySystemTypePageReqVO;
import com.smartleanx.module.hrm.controller.admin.companysystemtype.vo.CompanySystemTypeRespVO;
import com.smartleanx.module.hrm.dal.dataobject.companysystemtype.CompanySystemTypeDO;
import com.smartleanx.module.hrm.service.companysystemtype.CompanySystemTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

@Tag(name = "员工PC端 - 公司制度库分类")
@RestController
@RequestMapping("/hrm/pc-company-system-type")
@Validated
public class PCCompanySystemTypeController {

    @Resource
    private CompanySystemTypeService companySystemTypeService;

    @GetMapping("/get")
    @Operation(summary = "获得公司制度库分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<CompanySystemTypeRespVO> getCompanySystemType(@RequestParam("id") Long id) {
        CompanySystemTypeDO companySystemType = companySystemTypeService.getCompanySystemType(id);
        return success(BeanUtils.toBean(companySystemType, CompanySystemTypeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得公司制度库分类分页")
    @PreAuthenticated
    public CommonResult<PageResult<CompanySystemTypeRespVO>> getCompanySystemTypePage(@Valid CompanySystemTypePageReqVO pageReqVO) {
        PageResult<CompanySystemTypeDO> pageResult = companySystemTypeService.getCompanySystemTypePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CompanySystemTypeRespVO.class));
    }


    @GetMapping("/getList")
    @Operation(summary = "获得公司制度库分类列表")
    @PreAuthenticated
    public CommonResult<List<CompanySystemTypeRespVO>> getCompanySystemTypeList(@RequestParam("name") String name) {
        List<CompanySystemTypeDO> typeList = companySystemTypeService.getCompanySystemTypeList(name);
        return success(BeanUtils.toBean(typeList, CompanySystemTypeRespVO.class));
    }

    @GetMapping("/getSystemTypeTreeByUser")
    @Operation(summary = "构建首页制度库分类列表（用户端）")
    @PreAuthenticated
    public CommonResult<List<CompanySystemTypeRespVO>> getSystemTypeTreeByUser(@RequestParam("learnStatus") Integer learnStatus, @RequestParam("typeId") Long typeId) {
        return success(companySystemTypeService.getSystemTypeTreeByUser(learnStatus,typeId,null));
    }

    @GetMapping("/getCompanySystemParentList")
    @Operation(summary = "获取首页公司制度分类")
    @PreAuthenticated
    public CommonResult<List<CompanySystemTypeDO>> getCompanySystemParentList(){
        return success(companySystemTypeService.getCompanySystemParentList());
    }

}
